package com.shop.mapper;

import com.github.pagehelper.Page;
import com.shop.annotation.AutoFill;
import com.shop.dto.DiscountPageQueryDTO;
import com.shop.entity.Discount;
import com.shop.enumeration.OperationType;
import com.shop.vo.DiscountVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DiscountMapper {
    /**
     * 根据商品id查询折扣数量
     *
     * @param productId
     * @return
     */
    @Select("select count(id) from discount where product_id = #{productId}")
    Integer countByProductId(Long productId);

    /**
     * 插入折扣数据
     *
     * @param discount
     */
  //  @AutoFill(value = OperationType.INSERT)
    void insert(Discount discount);

    /**
     * 分页查询折扣数据
     *
     * @param discountPageQueryDTO
     * @return
     */
    Page<DiscountVO> pageQuery(DiscountPageQueryDTO discountPageQueryDTO);

    /**
     * 根据主键查询折扣
     *
     * @param id
     * @return
     */
    @Select("select * from discount where id = #{id}")
    Discount getById(Long id);

    /**
     * 根据主键删除折扣数据
     *
     * @param id
     */
    @Delete("delete from discount where id = #{id}")
    void deleteById(Long id);

    /**
     * 更新折扣数据
     *
     * @param discount
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Discount discount);

    /**
     * 查询折扣数据列表
     *
     * @param discount
     * @return
     */
    List<Discount> list(long discount);
}